/**
 * @(#) NXTLightActuator.java
 */

package pcsr.drivers.nxtDriver;

import pcsr.drivers.nxtDriver.command.INXTCommand;

class NXTLightActuator extends NXTActuator
{
	protected NXTLightActuator( NXTPort motor, INXTCommand command ) {
		super(motor, command);
		
		super.SetRunState(NXTActuatorRunState.RUNNING);
	}

	/**
	 * Turns on the light.
	 * @return Intensity of light
	 */
	public synchronized int TurnOn( )
	{
		SetMode(NXTActuatorMode.MOTORON);
		if(SetActuatorState() == 0)
			return GetPower();
		return -1;
	}
	
	/**
	 * Turns off the light.
	 * @return Intensity of light
	 */
	public synchronized int TurnOff( )
	{
		SetMode(NXTActuatorMode.BRAKE);
		if(SetActuatorState() == 0)
			return GetPower();
		return -1;
	}
	
	/**
	 * Sets the light intensity.
	 * @param intensity Intensity of light [0;100]
	 */
	public synchronized void SetIntensity( int intensity )
	{
		SetPower((byte)intensity);
		SetActuatorState();
	}
	
	/**
	 * Gets the light intensity.
	 * @return Intensity of light [0;100]
	 */
	public int GetIntensity( )
	{
		UpdateActuatorState();		
		return GetPower();
	}

	@Override
	public double GetActuatorValue( ) {
		return GetIntensity();
	}

	@Override
	public void SetActuatorValue( double value ) {
		SetIntensity((int) value);
	}
	
	@Override
	public NXTActuatorMode[] GetAvailableModes( ) {
		return new NXTActuatorMode[]{NXTActuatorMode.BRAKE, NXTActuatorMode.MOTORON};
	}
	
	@Override
	public void SetRunState( NXTActuatorRunState runstate )
	{
		super.SetRunState(NXTActuatorRunState.RUNNING);
	}
}
